﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FatHibernation.Utilities.DesignByContract;

namespace FatHibernation.Utilities
{
    public class StringGenerator
    {

        public static string GenerateAlphaNumericalCode(byte length)
        {
            Check.Require(length > 0, "Length must be > 0");

            string returnString;
            long i = 1;
            foreach (byte b in Guid.NewGuid().ToByteArray())
            {
                i *= ((int)b + 1);
            }
            returnString = string.Format("{0:x}", i - DateTime.Now.Ticks);
            returnString = returnString.Substring(0, length);
            Check.Ensure(returnString.Length == length, "Incorrect length.");
            return returnString;
        }
    }
}